package com.itheima;
//【断言型接口 - Predicate】
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

public class Demo4 {
    public static void main(String[] args) {
        List<String> strings = Arrays.asList("123", "123456",
                "abcdef", "abc123", "ab123cd", "7654321", "123abc",
                "123s456", "123456789123");
        List<String> filterStrs = filterStr(strings,
                s -> s.length() >= 5 && s.length() <= 10,
                s -> {
                for (int i = 0; i < s.length(); i++) {
                        char ch = s.charAt(i);
                        if (ch < '0' || ch > '9') {
                            return false;
                        }
                    }
                    return true;
                });
        // 遍历
        filterStrs.forEach(System.out::println);
         filterStrs.forEach(s -> System.out.println(s));

    }

    public static List<String> filterStr(List<String> strs,
                Predicate<String> pre1, Predicate<String> pre2){
        List<String> list = new ArrayList<>();
        for (String str : strs) {
            if (pre1.and(pre2).test(str))
                list.add(str);
        }
        return  list;
    }
}
